<template>
  <div class="page-container">
    <el-dialog title="批次" width="70%" :visible.sync="itemDialogVisible"   @opened="findPage(1)"   :before-close="handleClose">
        <div class="gk-layout-container">
              <div class="gk-layout-header">
                <s-query perms="material:item"   @click="findPage"   > 
                    <el-form-item>
                      <el-input v-model.trim="filters.batchNo"  placeholder="请输入内部批号"></el-input>
                    </el-form-item>
                </s-query>
              </div> 
              <div class="gk-layout-main"  style="height:300px">
                    <my-table :data="pageResult.content"   :loading="loading"  @selection-change="selectionChange"  >
                          <el-table-column :label="$t('action.desc')" width="50" fixed="left"  header-align="center" align="center">
                            <template slot-scope="scope">   {{scope.$index+1}}   </template>
                          </el-table-column> 
                            <el-table-column type="selection" width="40"  ></el-table-column>
                          <column   prop="batchNo" label="订单号"   />
                          <column  prop="itemId" label="物料名称"     key="itemId" :formatter= "selectionFormats" />  
                          <column  prop="count" label="数量"   /> 
                          <el-table-column :label="$t('action.operation')" width="100" fixed="right"   header-align="center" align="center">
                            <template slot-scope="scope">
                              <kt-button icon="fa fa-trash" :label="$t('action.Select')" perms="sys:user:delete"  :size="size" type="danger" @click="handleSelectSingle(scope.row)" />
                            </template>
                        </el-table-column>
                    </my-table>
                </div>
          
                <div class="toolbar gk-layout-footer"  style="padding:10px;">
                    <el-button :size="size" @click.native="handleClose" style="float:left;" >{{$t('action.cancel')}}</el-button>
                    <kt-button :label="$t('action.batchSelect')"  perms="sys:user:delete"     :size="size" type="danger" @click="handleSelect()" 
                      :disabled="this.selections.length===0" style="float:left;" />
                      <el-pagination layout="total, prev, pager, next, jumper"  @current-change="findPage"
                                    :current-page="filters.pageNum"
                                    :page-size="filters.pageSize"
                                    :total="pageResult.totalSize"
                                    style="float:right;">
                      </el-pagination>
                </div>
          </div>
        
    </el-dialog>
  </div>
</template>

<script>
import PopupTreeInput from "@/components/PopupTreeInput" 
import KtButton from "@/views/Core/KtButton"
import MyTable from "@/views/Core/MyTable"
import Column from "@/views/Core/Column"
import { format } from "@/utils/datetime"
import SQuery from "@/components/Kj/SQuery"
export default {
  components: {
    PopupTreeInput,
    KtButton,
    Column,
    MyTable,
    SQuery
  },
  props:{
	    itemDialogVisible:{
			type: Boolean
    },
      type:{
        type: Number
      }
	},
  data () {
    return {
      size: 'small',
      filters: {
        batchNo: '',
        businessStatus:0,
        itemId:'',
        id:'',
        type:0,
        pageNum: 1, pageSize: 5
      },
      loading:false, 
      Items: [],	
      selections: [] , // 列表选中列
      pageResult: {}
    }
  },
 
  methods: {
    //获取分页数据
    findPage: function (data) {
       if(data!=-1){
				this.filters.pageNum=data	
			} 
      this.$api.batch.findPage(this.filters).then((res) => {
        this.pageResult = res.data 
      }) 
    },
    selectionChange: function (selections) {
      this.selections = selections;
    }, 
    handleSelect: function (data) {
      	let ids = this.selections.map(item => item.id).toString();
        this.$emit('handleSelect', ids)
    },
    handleSelectSingle: function (row) {
        this.$emit('handleSelect', row.id)
    }, 
		findItems: function () {
			this.$api.item.findAll().then((res) => {
				this.Items = res.data			
			})
		},
    handleClose:function(){
        this.$emit('itemHidden', {})
        done();
    },	
    selectionFormats: function (row, column, cellValue, index) {
				let key = ""
				let propt = column.property;
				let val = row[column.property];				
				let dict = this.Items;
				for (let i = 0; i < dict.length; i++) {
					if (dict[i].i == val) {
					return dict[i].n;
					}
				}
				return row[column.property]
			}
  },
  mounted () {
      this.findItems();
       this.findPage(1);
  }
}
</script>

<style scoped>
</style>